type MenuItem = {
    title: string,
    name: string,
    icon: string,
    redirect:string|null,
    children: MenuItem[]|null,
}
export default function  createRouteMap(menus:MenuItem[]) {
    const routeMap = new Map<string,MenuItem>();
    const parentMap = new Map<string,MenuItem>();

    function traverse(menuList:MenuItem[], parent:MenuItem | null = null) {
        menuList.forEach(menu => {
            // 映射路由名到菜单项
            routeMap.set(menu.name, menu);

            // 记录父子关系
            if (parent) {
                parentMap.set(menu.name, parent);
            }

            // 递归处理子菜单
            if (menu.children && menu.children.length > 0) {
                traverse(menu.children, menu);
            }
        });
    }

    traverse(menus);
    return { routeMap, parentMap };
}
